package adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import custom.Commody_secKill;
import entity.SecKillEntity;

/**
 * Created by Mr.xingkong on 2016/1/13.
 */
public class SecKillListAdapter extends BaseAdapter implements View.OnClickListener {
    Context context;
    List<SecKillEntity.DataEntity.ProductListEntity> data;
    public SecKillListAdapter(Context context)
    {
        this.context = context;
        this.data = new ArrayList<>();
    }

    public void setData( List<SecKillEntity.DataEntity.ProductListEntity> data)
    {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        Commody_secKill commody_secKill =  new Commody_secKill(context);
        convertView = commody_secKill;

        String price = "¥"+data.get(position).getPriceStr();
        String oriPrice = "¥"+data.get(position).getOriginalPriceStr();
        int stock = data.get(position).getStock();
        if(stock < 1){
            commody_secKill.limitNum.setClickable(false);
            commody_secKill.willStart.setClickable(false);
        }
        commody_secKill.willStart.setOnClickListener(this);
        commody_secKill.limitNum.setOnClickListener(this);
        commody_secKill.setData(data.get(position).getImgUrl(),price,oriPrice,data.get(position).getTitle());

        return convertView;
    }

    @Override
    public void onClick(View v)
    {
        Toast.makeText(context, "OK", Toast.LENGTH_SHORT).show();
    }
}
